// 格式化课程时间显示
export const formatCourseTime = (timeStr) => {
    if (!timeStr) return '-';

    const days = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"];

    try {
        const parts = timeStr.split('-').map(Number);
        if (parts.length !== 3) return timeStr;

        const [day, start, length] = parts;

        // 验证数据有效性
        if (day < 1 || day > 7 || start < 1 || start > 9 || length < 1) {
            return timeStr;
        }

        const end = start + length - 1;
        return `${days[day - 1]} 第${start}-${end}节`;
    } catch (error) {
        return timeStr;
    }
};

// 解析时间字符串
export const parseTimeString = (timeStr) => {
    if (!timeStr) return { weekday: '', section: '', length: '' };

    const parts = timeStr.split('-');
    if (parts.length === 3) {
        return {
            weekday: parts[0],
            section: parts[1],
            length: parts[2]
        };
    }
    return { weekday: '', section: '', length: '' };
};